package com.droidblackbox.manager;

import android.util.Log;

public class Logger {

    public static final String MAIN;
    public static final String RECORD;
    public static final String HISTORY;
    public static final String LOG;
    public static final String PREFERENCE;

    static {
	MAIN = "DroidBlackBox";
	RECORD = "DroidBlackBox.Record";
	HISTORY = "DroidBlackBox.History";
	LOG = "DroidBlackBox.Log";
	PREFERENCE = "DroidBlackBox.Preference";

    }

    private static Logger instance = null;

    private synchronized static Logger getInstance() {
	if (instance == null) {
	    synchronized (Logger.class) {
		if (instance == null) {
		    instance = new Logger();
		}
	    }
	}
	return instance;
    }

    private Logger() {
    }

    private static String createMessage(String filter, String methodName,
	    String message) {
	getInstance();
	StringBuffer msgBuf = new StringBuffer();
	msgBuf.append("[");
	msgBuf.append(filter);
	msgBuf.append("][");
	msgBuf.append(methodName);
	msgBuf.append("] ");
	msgBuf.append(message);

	return msgBuf.toString();
    }

    public static void error(String fileName, String filter, String methodName,
	    String message) {
	getInstance();
	Log.e(fileName + ".java", createMessage(filter, methodName, message));
    }

    public static void debug(String fileName, String filter, String methodName,
	    String message) {
	getInstance();
	Log.d(fileName + ".java", createMessage(filter, methodName, message));
    }

    public static void info(String fileName, String filter, String methodName,
	    String message) {
	getInstance();
	Log.i(fileName + ".java", createMessage(filter, methodName, message));
    }

    public static void verbose(String fileName, String filter,
	    String methodName, String message) {
	getInstance();
	Log.v(fileName + ".java", createMessage(filter, methodName, message));
    }

    public static void warning(String fileName, String filter,
	    String methodName, String message) {
	getInstance();
	Log.w(fileName + ".java", createMessage(filter, methodName, message));
    }
}
